package com.ggb.readingtime.model

import com.ggb.readingtime.constants.*
import io.swagger.v3.oas.annotations.media.Schema
import lombok.Data


@Data
@Schema(title="返回结果 Result")
data class Result<T>(
    val code: Int,
    val msg: String?,
    val data: T?
){
    companion object {
        fun <T> success(): Result<T> = Result(
            code = 1,
            msg = ACTION_SUCCESS,
            data=null
        )

        fun <T> success(data: T): Result<T> = Result(
            code = 1,
            msg = ACTION_SUCCESS,
            data = data
        )

        fun <T> error(msg: String): Result<T> = Result(
            code = 0,
            msg = msg,
            data=null
        )
    }
}